package com.jz.community.modulemine.presenter;

import com.jz.community.basecomm.bean.BaseResponseText;
import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.modulemine.bean.VersionBean;
import com.jz.community.modulemine.model.MineModel;
import com.jz.community.modulemine.model.MineModelImp;
import com.jz.community.modulemine.ui.SettingView;

/**
 * Created by Admin on 2018/4/4 0004.
 */

public class SettingPresenter extends BaseLifeCyclePresent<SettingView.View> implements SettingView.Presenter {


    private SettingView.View view;
    private MineModel mineModel;

    public SettingPresenter(SettingView.View view) {
        this.view = view;
        this.mineModel = new MineModelImp(view.getContext());
    }

    @Override
    public void memberLoginOut(String token) {
        mineModel.memberLoginOut(token, new OnLoadListener<BaseResponseText>() {
            @Override
            public void onSuccess(BaseResponseText responseText) {
                view.loginOutResult(responseText);
            }

            @Override
            public void onFail(String s, int code) {

            }
        });
    }

    @Override
    public void updateVersion(String versionName) {
        mineModel.updateVersion(versionName, new OnLoadListener<VersionBean>() {
            @Override
            public void onSuccess(VersionBean versionBean) {
                view.setUpdateData(versionBean);
            }

            @Override
            public void onFail(String msg, int code) {
                if (code != 204 && code != 303) {
                    view.showError(msg);
                }
            }
        });

    }
}
